<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org" th:with="title='发布文章',active='publish'">
<header th:replace="back/header::headerFragment(${title},${active})"></header>
<link th:href="@{/back/plugins/tagsinput/jquery.tagsinput.css}" rel="stylesheet"/>
<link th:href="@{/back/plugins/select2.dist.css/select2-bootstrap.css}" rel="stylesheet"/>
<link th:href="@{/back/plugins/toggles/toggles.css}" rel="stylesheet"/>

<link th:href="@{/back/plugins/mditor/css/mditor.min.css}" rel="stylesheet"/>
<link th:href="@{/back/plugins/dropzone/4.3.0/min/dropzone.min.css}" rel="stylesheet">
<style>
    #tags_tagsinput {
        background-color: #fafafa;
        border: 1px solid #eeeeee;
    }

    #tags_addTag input {
        width: 100%;
    }

    #tags_addTag {
        margin-top: -5px;
    }

    .mditor .editor{
        font-size: 14px;
        font-family: "Helvetica Neue",Helvetica,Arial,sans-serif;
    }
    .mditor .backdrop, .mditor .textarea, .mditor .viewer{
        font-size: 14px;
    }
    .markdown-body{
        font-size: 14px;
    }
    .note-toolbar {
        text-align: center;
    }

    .note-editor.note-frame {
        border: none;
    }

    .note-editor .note-toolbar {
        background-color: #f5f5f5;
        padding-bottom: 10px;
    }

    .note-toolbar .note-btn-group {
        margin: 0;
    }

    .note-toolbar .note-btn {
        border: none;
    }

    #articleForm #dropzone {
        min-height: 200px;
        background-color: #dbdde0;
        line-height:200px;
        margin-bottom: 10px;
    }
    #articleForm .dropzone {
        border: 1px dashed #8662c6;
        border-radius: 5px;
        background: white;
    }
    #articleForm .dropzone .dz-message {
        font-weight: 400;
    }
    #articleForm .dropzone .dz-message .note {
        font-size: 0.8em;
        font-weight: 200;
        display: block;
        margin-top: 1.4rem;
    }
    .publish-card {
        background: #fff;
        border-radius: 14px;
        box-shadow: 0 4px 24px rgba(60,60,60,0.08);
        padding: 32px 28px 24px 28px;
        margin-top: 24px;
        margin-bottom: 24px;
    }
    .publish-title {
        display: flex;
        align-items: center;
        font-size: 26px;
        font-weight: 600;
        color: #4a4a4a;
        background: linear-gradient(90deg,#f5f7fa 60%,#e3e6ec 100%);
        border-radius: 12px 12px 0 0;
        box-shadow: 0 2px 8px #e3e6ec;
        padding: 18px 24px 14px 18px;
        margin-bottom: 0;
    }
    .publish-title i {
        color: #8662c6;
        font-size: 30px;
        margin-right: 16px;
    }
    .publish-form .form-control {
        border-radius: 8px;
        box-shadow: 0 1px 4px #f0f0f0;
        border: 1px solid #e0e0e0;
        transition: border-color 0.2s, box-shadow 0.2s;
    }
    .publish-form .form-control:focus {
        border-color: #8662c6;
        box-shadow: 0 2px 8px #e1bee7;
    }
    #md-container {
        border-radius: 8px;
        box-shadow: 0 2px 8px #e3e6ec;
        background: #fafbfc;
        padding: 12px 8px 8px 8px;
        margin-bottom: 18px;
    }
    .publish-form .btn {
        border-radius: 8px;
        font-size: 18px;
        padding: 8px 32px;
        box-shadow: 0 2px 8px #e3e6ec;
        transition: background 0.2s, box-shadow 0.2s;
    }
    .publish-form .btn-primary {
        background: linear-gradient(90deg,#8662c6 60%,#a084e8 100%);
        border: none;
    }
    .publish-form .btn-primary:hover {
        background: linear-gradient(90deg,#a084e8 60%,#8662c6 100%);
        box-shadow: 0 4px 16px #b39ddb;
    }
    .publish-form .btn-default {
        background: #f5f5f5;
        border: none;
    }
    .publish-form .btn-default:hover {
        background: #e0e0e0;
    }
    .publish-form .form-group {
        margin-bottom: 22px;
    }
</style>
<body class="fixed-left">
<div id="wrapper">
    <div th:replace="back/header::header-body"></div>
    <div class="content-page">
        <div class="content">
            <div class="container">
                <div class="row">
                    <div class="col-sm-12">
                        <div class="publish-title">
                            <i class="fa fa-pencil-square-o"></i>
                            <span>
                                <th:block th:if="${null != contents}">编辑文章</th:block>
                                <th:block th:unless="${null != contents}">发布文章</th:block>
                            </span>
                        </div>
                    </div>
                    <div class="col-md-12">
                        <div class="publish-card">
                            <form id="articleForm" class="publish-form">
                                <input type="hidden" name="id"
                                       th:value="${contents!=null and contents.id!=null}?${contents.id}: ''" id="id"/>
                                <input type="hidden" name="allowComment"
                                       th:value="${contents!=null and contents.allowComment !=null}
                                       ?${contents.allowComment}: true" id="allow_comment"/>
                                <input type="hidden" name="content" id="content-editor"/>
                                <input type="hidden" th:name="${_csrf.parameterName}" th:value="${_csrf.token}"/>
                                <div class="form-group col-md-6" style="padding: 0 10px 0 0;">
                                    <th:block th:if="${null != contents}">
                                        <input type="text" class="form-control" name="title"
                                               required="required" aria-required="true" th:value="${contents.title}"/>
                                    </th:block>
                                    <th:block th:unless="${null != contents}">
                                        <input type="text" class="form-control" placeholder="请输入文章标题（必须）" name="title"
                                               required="required" aria-required="true"/>
                                    </th:block>
                                </div>
                                <div class="form-group col-md-6" style="padding: 0 10px 0 0;">
                                    <th:block th:if="${null != contents}">
                                        <input name="tags" id="tags" type="text" class="form-control" th:value="${contents.tags}" />
                                    </th:block>
                                    <th:block th:unless="${null != contents}">
                                        <input name="tags" id="tags" type="text" class="form-control" placeholder="请输入文章标签" />
                                    </th:block>
                                </div>
                                <div class="form-group col-md-6" style="padding: 0 10px 0 0;">
                                    <label>分类</label>
                                    <select class="form-control" name="categoryId" required>
                                        <option value="">请选择分类</option>
                                        <th:block th:each="cat : ${categoriesList}">
                                            <option th:value="${cat.id}" th:text="${cat.name}" th:selected="${contents!=null and contents.categoryId==cat.id}"></option>
                                        </th:block>
                                    </select>
                                </div>
                                <div class="clearfix"></div>
                                <div id="md-container" class="form-group">
                                    <textarea id="md-editor" th:utext="${contents!=null and contents.content !=null}?${contents.content}: ''"></textarea>
                                </div>
                                <div class="clearfix"></div>
                                <div class="text-right">
                                    <a class="btn btn-default waves-effect waves-light" th:href="@{/admin/article}">返回列表</a>
                                    <button type="button" class="btn btn-primary waves-effect waves-light" onclick="subArticle('publish');">
                                        保存文章
                                    </button>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
                <div th:replace="back/footer :: footer-content"></div>
            </div>
        </div>
    </div>
</div>
<div th:replace="back/footer :: footer"></div>

<script th:src="@{/back/plugins/tagsinput/jquery.tagsinput.min.js}"></script>
<script th:src="@{/back/plugins/jquery-multi-select/jquery.quicksearch.js}"></script>

<script th:src="@{/back/plugins/mditor/js/mditor.min.js}"></script>
<script th:src="@{/back/plugins/multi-select/0.9.12/js/jquery.multi-select.min.js}"></script>
<script th:src="@{/back/plugins/select2/3.4.8/select2.min.js}"></script>
<script th:src="@{//cdn.bootcss.com/jquery-toggles/2.0.4/toggles.min.js}"></script>
<script th:src="@{/back/plugins/dropzone/4.3.0/min/dropzone.min.js}"></script>
<script th:src="@{/back/plugins/to-markdown/3.1.0/to-markdown.min.js}"></script>

<script th:src="@{/back/js/article.js}"></script>
</body>
</html>